package dongshi.daddy.prototype.prototypemanager.manager;

import dongshi.daddy.prototype.prototypemanager.product.Circle;
import dongshi.daddy.prototype.prototypemanager.product.Shape;
import dongshi.daddy.prototype.prototypemanager.product.Square;

import java.util.HashMap;

public class ProtoTypeManager {
    private HashMap<String, Shape> ht = new HashMap<String, Shape>();

    public ProtoTypeManager() {
        ht.put("Circle", new Circle());
        ht.put("Square", new Square());
    }

    public void addshape(String key, Shape obj) {
        ht.put(key, obj);
    }

    public Shape getShape(String key) {
        Shape temp = ht.get(key);
        // 每次克隆新的，但是注意，这里是浅拷贝，实际中还是深拷贝，避免出现多个对象的引用类型属性指向同一个对象的情况
        return (Shape) temp.clone();
    }
}
